package com.tbit.uqbike.push.pojo.dto;


/**
 * @author: Kang
 * @date: 2018年5月17日 下午3:29:20
 * @description: Json返回结果集合
 */
public class JsonResult {
    private Integer ret;
    private String msg;
    private Object data;
    private String traceId;

    private JsonResult(Object data, Integer ret) {
        this.data = data;
        this.ret = ret;
    }

    private JsonResult(String msg, Integer ret, String traceId) {
        this.msg = msg;
        this.ret = ret;
        this.traceId = traceId;
    }

    private JsonResult() {

    }

    /**
     * 返回结果成功时，有data,ret=1
     *
     * @param data
     * @return
     */
    public static JsonResult ok(Object data) {
        JsonResult result = new JsonResult(data, 1);
        if (result.getData() == null) {
            result.setData(new Object());
        }
        return result;
    }

    /**
     * 返回结果成功时，无data,ret=1
     *
     * @return
     */
    public static JsonResult buildHasNoData() {
        JsonResult result = new JsonResult();
        result.setRet(1);
        return result;
    }

    /**
     * 返回结果失败时，包含错误信息msg，以及错误码code
     *
     * @param msg
     * @return
     */
    public static JsonResult fail(String msg, String traceId) {
        return new JsonResult(msg, 0, traceId);

    }

    public Integer getRet() {
        return ret;
    }

    public void setRet(Integer ret) {
        this.ret = ret;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }
}
